package leetcode.code1710;

import java.util.Arrays;

public class Solution {
	public int maximumUnits(int[][] boxTypes, int truckSize) {
		Arrays.sort(boxTypes, (a, b) -> b[1] - a[1]);
		int ans = 0;
		for (int i = 0; i < boxTypes.length && truckSize > 0; i++) {
			int box = boxTypes[i][0], unit = boxTypes[i][1];
			int cur = Math.min(box, truckSize);
			ans += cur * unit;
			truckSize -= cur;
		}
		return ans;
	}
}
